
// 总部采购单据
function pocureDocuments(data) {
	// 单据时间
	var time = data.creationTime.substring(0, 10);
	// 经手人
	var auditorName = data.orderCounter;
	// 供应商名称
	var clientName = data.supplier;
	// 库房
	var storeName = data.storeName;
	// 单据号
	var id = data.id;
	// 备注信息
	var comment = data.comment;
	// 取循环次数(打印页数）
	var counts = parseInt(data.products.length / 18);
	// 取余数
	var end = data.products.length % 18;
	// 合计数量
	var amountTo = data.totalQuantity;
	// 合计金额
	var totalAmount = data.totalWholePrice;
	// 判断采购单据类型
	var pocureType = data.typeS;
	// 单据总页数
	var pageNum = parseInt(counts) + 1;
	for (i = 1; i <= pageNum; i++) {
		console.log("总页数："+pageNum)
		
		if (i == pageNum) {
			//没有余数,并且是最后一页,则总计单起一页
			if(end == 0  && i == pageNum ){
				var sum = "";
				sum += "<tr><td>总合计</td><td></td><td></td><td></td><td>"+amountTo+"</td><td></td><td>"+totalAmount+"</td></tr>\n";
				procurePrint(pageNum,i,pocureType, time, auditorName, clientName,sum,id,comment);
				console.log(sum);
			}else {
				var endInfo = "";
				var sumNumber = 0;
				var sum = 0;
				var infoEnd = data.products.slice(counts * 18, counts * 18 + end);
				for (y = 0; y < infoEnd.length; y++) {
					endInfo += "<tr><td>" + infoEnd[y].year + infoEnd[y].brand
							+ infoEnd[y].quarter + "</td><td>"
							+ infoEnd[y].productCode + infoEnd[y].color
							+ "</td><td>" + infoEnd[y].category + "</td><td>"
							+ infoEnd[y].unit + "</td><td>" + infoEnd[y].quantity
							+ "</td><td>" + infoEnd[y].recCost
							+ "</td><td>" + infoEnd[y].totalRecCost
							+ "</td></tr>\n" 
					sumNumber += parseInt(infoEnd[y].quantity);
					sum += parseInt(infoEnd[y].totalRecCost);
					// 最后一行算合计
					if (y == infoEnd.length - 1) {
						endInfo += "<tr><td>页小计</td><td></td><td></td><td></td><td>" + sumNumber +"</td><td></td><td>"+ sum + "</td></tr>\n" +
								"<tr><td>总合计</td><td></td><td></td><td></td><td>"+amountTo+"</td><td></td><td>"+totalAmount+"</td></tr>\n" 	
					}
				}
				//procurePrint(pageNum,i, pocureType,storeName,time, auditorName, clientName,endInfo,id,comment);
				console.log(endInfo);
			}	
		} else {
			var info = "";
			var sumNumber = 0;//数量小计
			var sum = 0; // 金额小计
			var infoTwo = data.products.slice((i - 1) * 18, (i - 1) * 18 + 18);
			for (z = 0; z < infoTwo.length; z++) {
				info += "<tr><td>" + infoTwo[z].year + infoTwo[z].brand
						+ infoTwo[z].quarter + "</td><td>"
						+ infoTwo[z].productCode + infoTwo[z].color
						+ "</td><td>" + infoTwo[z].category + "</td><td>"
						+ infoTwo[z].unit + "</td><td>" + infoTwo[z].quantity
						+ "</td><td>" + infoTwo[z].recCost
						+ "</td><td>" + infoTwo[z].totalRecCost
						+ "</td></tr>\n + "
				sumNumber += parseInt(infoTwo[z].quantity);
				sum += parseInt(infoTwo[z].totalRecCost);
				// 最后一行算合计
				if (z == infoTwo.length - 1) {
					info += "<tr><td>页小计</td><td></td><td></td><td></td><td>" + sumNumber +"</td><td></td><td>"+ sum + "</td></tr>\n +"
				}
			}
			//procurePrint(pageNum,i,pocureType,storeName, time, auditorName, clientName,info,id,comment);
			console.log(info);
		
		}
	}

}

// 采购单据打印输出方法
function procurePrint(pageNum, page, pocureType,storeName,time, auditorName, clientName, data,id,comment) {

	LODOP.PRINT_INITA(5,1,1183,600,"千禧总部——采购单小票打印");
	LODOP.SET_PRINT_PAGESIZE(1,2100,1400,"");
	LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE",1);
	LODOP.ADD_PRINT_TEXT(4,74,140,33,pocureType);
	LODOP.SET_PRINT_STYLEA(0,"FontSize",19);
	LODOP.SET_PRINT_STYLEA(0,"Bold",1);
	LODOP.ADD_PRINT_TEXT(9,225,408,27," 千禧宝贝品牌儿童服饰连锁(www.qxbaby.com)");
	LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
	LODOP.SET_PRINT_STYLEA(0,"Bold",1);
	LODOP.ADD_PRINT_TEXT(11,648,116,23,"共"+pageNum+"页 -  第"+page+"页      ");
	LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
	LODOP.ADD_PRINT_TEXT(37,5,758,25,"      日期： "+time+"     经手人：   "+auditorName+"           供应商:  "+clientName+"              库房：" +storeName);
	LODOP.ADD_PRINT_LINE(55, 75, 55, 170, 0, 0);
	LODOP.ADD_PRINT_LINE(55, 220, 55, 300, 0, 0);
	LODOP.ADD_PRINT_LINE(55, 370, 55, 510, 0, 0);
	
	LODOP.ADD_PRINT_TABLE(61,1,824,405,"<style> table,td,th {border: 1px solid black; border-style: solid;border-collapse: collapse;font-size:13px;}  td{text-align:center;}</style>\n"
							+ "<table border='1'  width='760px'><tr><td style='width:180px;'>商品名称</td><td style='width:150px'>商品型号</td><td style='width:110px'>商品类型</td><td style='width:60px'>单位</td><td style='width:60px'>数量</td><td style='width:60px'>单价</td><td style='width:80px'>金额</td></tr>\n"
							+data
							+ "</table>");

	LODOP.ADD_PRINT_TEXT(431,1,756,20,"  单据号："+id+"                    备注："+comment);
	//打印预览
	//LODOP.PREVIEW();
	//打印设计
	//LODOP.PRINT_DESIGN();
	//直接打印（有水印）
	//LODOP.PRINT();
}